package cn.rengy.isql;

import cn.rengy.isql.entity.SqlRole;
import cn.rengy.lang.CacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.concurrent.Callable;
@Slf4j
public class SqlRoleService {
    private Dao dao;
    private CacheService cacheService;
    @Autowired
    private DbSqlValueService dbSqlValueService;

    public SqlRoleService(Dao dao,CacheService cacheService) {
        this.dao = dao;
        this.cacheService = cacheService;
    }


    public List<SqlRole> getSqlRole(String sqlAuthCode) {
        try {
            return cacheService.getCacheIncludeNull("sqlAuthCache", sqlAuthCode, () -> {
                SqlEntity sqlEntity = dbSqlValueService.getSqlEntityByName("selectRoleSqlByAuthCode");
                return dao.queryForBeanList(sqlEntity.getSql_value(), SqlRole.class, sqlAuthCode);
            });
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
